package com.gm.commonlib.network.basenetwork.numberformat;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;


public class StringDefault0Adapter extends TypeAdapter<String> {

    @Override
    public void write(JsonWriter out, String value) throws IOException {
        out.value(value);
    }

    @Override
    public String read(JsonReader in) throws IOException {
        if (in.peek() == JsonToken.NULL) {
            in.nextNull();
            return "";
        }

        try {
            String result = in.nextString();
            if(result.equals("") || result.equals("null")) {
                return "";
            }
            return result;
        } catch (Exception e) {
            return "";
        }
    }
}

